
enum FUN_LIST {
    //% block="X轴加速度"
     x,
    //% block="Y轴加速度"
     y,
    //% block="Z轴加速度"
     z
}



//% color="#5ba55b" iconWidth=50 iconHeight=40
namespace MSA311 { 

    //% block="读取加速度传感器" blockType="command"
     export function read_accel(parameter: any, block: any) {
        
        Generator.addInclude('#include_Wire_h>', '#include <Wire.h>');
        Generator.addInclude('#include_Adafruit_MSA301_h', '#include <Adafruit_MSA301.h>"');
        Generator.addInclude('#include_Adafruit_Sensor_h', '#include <Adafruit_Sensor.h>"');
        Generator.addObject(`Adafruit_MSA301_msa`, `Adafruit_MSA311`, `msa;`);
        Generator.addSetup(`msa_begin`, `msa.begin();`);
        Generator.addCode(`msa.read();`);
    }  
    //% block="返回加速度传感器的 [FUN]" blockType="reporter"
    //% FUN.shadow="dropdown" FUN.options="FUN_LIST" 
     export function return_accel(parameter: any, block: any) {
        let fun = parameter.FUN.code;
       //Generator.addInclude('#include_Wire_h>', '#include <Wire.h>');
       //Generator.addInclude('#include_Adafruit_MSA301_h', '#include <Adafruit_MSA301.h>"');
       //Generator.addInclude('#include_Adafruit_Sensor_h', '#include <Adafruit_Sensor.h>"');
       //Generator.addObject(`Adafruit_MSA301_msa`, `Adafruit_MSA311`, `msa;`);
        Generator.addCode(`msa.${fun}`);
    } 
}
